/**
 * Copyright millionhere
 * Licensed under the Apache License, Version 2.0 (the "License");
 * You may see it at...
 *      http://www.apache.org/licenses/LICENSE-2.0
 */

package info.millionhere.keepsilent;

import java.util.HashMap;

@SuppressWarnings("serial")
public class DealWithCountryCallingCodes {
    
    static final String prefixCountryCallingCodes = "+";
    
//    static final String[] CountryCallingCodes = {"+86", "+1", "+81", "+82", "+852", "+853", "+886", "+91"};
    
    static final HashMap<String, String> CountryIsoCallingCodeMap = new HashMap<String, String>(){{
	put("cn","+86");
	put("us","+1");
	put("jp","+81");
	put("kr","+82");
	put("hk","+852");
	put("mo","+853");
	put("tw","+886");
	put("in","+91");
    }};
    
    public static String removeCountryCallingCodes(String address){
	for (String t:CountryIsoCallingCodeMap.values()){
	    if (address.contains(t)){
		return address.replace(t, "");
	    }
	}
	return address;
    }
    public static boolean bHaveCountryCallingCodes(String address){
	return address.contains(prefixCountryCallingCodes);
    }
    
    public static String transCountryIsoToCountryCallingCode(String countryIso){
	return CountryIsoCallingCodeMap.get(countryIso.toLowerCase());
    }
}
